{smcl}
{com}{sf}{ul off}{txt}{.-}
      name:  {res}<unnamed>
       {txt}log:  {res}C:\Users\nkalmoe\Dropbox\Research\A Publishing\Finished\PSRM - VCM Partic\Kalmoe - Fig A1, Study 2.smcl
  {txt}log type:  {res}smcl
 {txt}opened on:  {res}14 Jun 2017, 10:53:45

{com}. do "C:\Users\nkalmoe\Dropbox\Research\A Publishing\Finished\PSRM - VCM Partic\PSRM - Kalmoe Fig A1, Studies 1 & 2.do"
{txt}
{com}. ***Remember the order of variables is X, Z, W. ***
. ***On the graph, W represents the different lines.  I set them to W0=-1SD PAGG W1=50% W2=+1SD W3=95%***
. 
. * two-sided, p<.05=1.96, p<.1=1.645
. * y = x z w xz xw zw xzw*
. * x(motive), z(aggress), w(Viol), y(dependent variable)
. *Estimating marginal effect of Violent Treatment, conditional on TA and group attitude
. reg vote viol aggress commitment violxaggress violxcommitment aggressxcommitment violxaggxcommit

      {txt}Source {c |}       SS       df       MS              Number of obs ={res}     396
{txt}{hline 13}{char +}{hline 30}           F(  7,   388) ={res}    7.66
    {txt}   Model {char |} {res} 4.28661884     7   .61237412           {txt}Prob > F      = {res} 0.0000
    {txt}Residual {char |} {res} 31.0257233   388  .079963204           {txt}R-squared     = {res} 0.1214
{txt}{hline 13}{char +}{hline 30}           Adj R-squared = {res} 0.1055
    {txt}   Total {char |} {res} 35.3123422   395  .089398335           {txt}Root MSE      = {res} .28278

{txt}{hline 20}{c TT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{col 1}               vote{col 21}{c |}      Coef.{col 33}   Std. Err.{col 45}      t{col 53}   P>|t|{col 61}     [95% Con{col 74}f. Interval]
{hline 20}{c +}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{space 15}viol {c |}{col 21}{res}{space 2} .5075362{col 33}{space 2} .1406793{col 44}{space 1}    3.61{col 53}{space 3}0.000{col 61}{space 4} .2309471{col 74}{space 3} .7841253
{txt}{space 12}aggress {c |}{col 21}{res}{space 2} .4808591{col 33}{space 2} .2902438{col 44}{space 1}    1.66{col 53}{space 3}0.098{col 61}{space 4}-.0897883{col 74}{space 3} 1.051506
{txt}{space 9}commitment {c |}{col 21}{res}{space 2}  .974212{col 33}{space 2} .2360341{col 44}{space 1}    4.13{col 53}{space 3}0.000{col 61}{space 4} .5101461{col 74}{space 3} 1.438278
{txt}{space 7}violxaggress {c |}{col 21}{res}{space 2}-1.063084{col 33}{space 2} .3494181{col 44}{space 1}   -3.04{col 53}{space 3}0.003{col 61}{space 4}-1.750073{col 74}{space 3} -.376094
{txt}{space 4}violxcommitment {c |}{col 21}{res}{space 2}-.8918659{col 33}{space 2} .2763535{col 44}{space 1}   -3.23{col 53}{space 3}0.001{col 61}{space 4}-1.435204{col 74}{space 3} -.348528
{txt}{space 1}aggressxcommitment {c |}{col 21}{res}{space 2}-1.184851{col 33}{space 2} .6280639{col 44}{space 1}   -1.89{col 53}{space 3}0.060{col 61}{space 4}-2.419685{col 74}{space 3} .0499838
{txt}violxaggxcommitment {c |}{col 21}{res}{space 2} 1.873233{col 33}{space 2} .7518757{col 44}{space 1}    2.49{col 53}{space 3}0.013{col 61}{space 4} .3949721{col 74}{space 3} 3.351493
{txt}{space 14}_cons {c |}{col 21}{res}{space 2} .3465785{col 33}{space 2} .1188038{col 44}{space 1}    2.92{col 53}{space 3}0.004{col 61}{space 4} .1129988{col 74}{space 3} .5801583
{txt}{hline 20}{c BT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{res}{txt}
{com}. 
. #delimit ;
{txt}delimiter now ;
{com}. *Estimating marginal effect of group attitude, conditional on TA and treatment*;
. egen zmin = min(aggress);
{txt}
{com}. egen zmax = max(aggress);
{txt}
{com}. gen z0 = (((_n-1)/(20-1))*(zmax-zmin))+zmin in 1/20;
{txt}(392 missing values generated)

{com}. generate Z=z0;
{txt}(392 missing values generated)

{com}. *     ****************************************************************  *;
. *       Generate the values of W for which you want to calculate the    *;
. *       marginal effect (and standard errors) of X on Y.                *;
. *     ****************************************************************  *;
. scalar W0=0;
{txt}
{com}. scalar W1=1;
{txt}
{com}. *     ****************************************************************  *;
. *       Grab elements of the coefficient and variance-covariance matrix *;
. *       that are required to calculate the marginal effect and standard *;
. *       errors.                                                         *;
. *     ****************************************************************  *;
. matrix b=e(b);
{txt}
{com}. matrix V=e(V);
{txt}
{com}. scalar b1=b[1,1];
{txt}
{com}. scalar b2=b[1,2];
{txt}
{com}. scalar b3=b[1,3];
{txt}
{com}. scalar b4=b[1,4];
{txt}
{com}. scalar b5=b[1,5];
{txt}
{com}. scalar b6=b[1,6];
{txt}
{com}. scalar b7=b[1,7];
{txt}
{com}. scalar varb1=V[1,1];
{txt}
{com}. scalar varb2=V[2,2];
{txt}
{com}. scalar varb3=V[3,3];
{txt}
{com}. scalar varb4=V[4,4];
{txt}
{com}. scalar varb5=V[5,5];
{txt}
{com}. scalar varb6=V[6,6];
{txt}
{com}. scalar varb7=V[7,7];
{txt}
{com}. scalar covb1b4=V[1,4];
{txt}
{com}. scalar covb1b5=V[1,5];
{txt}
{com}. scalar covb1b7=V[1,7];
{txt}
{com}. scalar covb4b5=V[4,5];
{txt}
{com}. scalar covb4b7=V[4,7];
{txt}
{com}. scalar covb5b7=V[5,7];
{txt}
{com}. scalar list b1 b2 b3 b4 b5 b6 b7 varb1 varb2 varb3 varb4 varb5 varb6 varb7 
>            covb1b4 covb1b5 covb1b7 covb4b5 covb4b7 covb5b7;
{txt}        b1 = {res} .50753617
{txt}        b2 = {res} .48085905
{txt}        b3 = {res} .97421199
{txt}        b4 = {res}-1.0630837
{txt}        b5 = {res}-.89186586
{txt}        b6 = {res}-1.1848507
{txt}        b7 = {res} 1.8732326
{txt}     varb1 = {res} .01979066
{txt}     varb2 = {res} .08424144
{txt}     varb3 = {res} .05571208
{txt}     varb4 = {res} .12209298
{txt}     varb5 = {res} .07637128
{txt}     varb6 = {res} .39446425
{txt}     varb7 = {res} .56531707
{txt}   covb1b4 = {res}-.03937736
{txt}   covb1b5 = {res}-.03566385
{txt}   covb1b7 = {res} .07143979
{txt}   covb4b5 = {res} .07240585
{txt}   covb4b7 = {res}-.23353907
{txt}   covb5b7 = {res}-.16134686
{txt}
{com}.            *     ****************************************************************  *;
. *       We want to calculate the marginal effect of X on Y for all      *;
. *       Z values of the modifying variable Z. We also want to          *;
. *       calculate this marginal effect as Z changes for specific values *;
. *       of the second modifying variable W.  In the code below, we      *;
. *       calculate the marginal effect of X on Y for all values of Z     *;
. *       when W=0, when W=1, when W=2, and when W=3.                     *;
. *     ****************************************************************  *;
. gen conb0=b1+b4*Z+b5*W0+b7*(Z*W0);
{txt}(392 missing values generated)

{com}. gen conb1=b1+b4*Z+b5*W1+b7*(Z*W1);
{txt}(392 missing values generated)

{com}. *     ****************************************************************  *;
. *       Calculate the standard errors for the marginal effect of X on Y *;
. *       for all Z values of the modifying variable Z. Do this for the  *;
. *       case when W=0, when W=1, when W=2, and when W=3.                *;
. *     ****************************************************************  *;
. gen conse0=sqrt(varb1
>                + varb4*(Z^2) + varb5*(W0^2) + varb7*(Z^2)*(W0^2)
>                + 2*Z*covb1b4 + 2*W0*covb1b5 + 2*Z*W0*covb1b7 + 2*Z*W0*covb4b5
>                + 2*W0*(Z^2)*covb4b7 + 2*(W0^2)*Z*covb5b7);
{txt}(392 missing values generated)

{com}. gen conse1=sqrt(varb1
>                + varb4*(Z^2) + varb5*(W1^2) + varb7*(Z^2)*(W1^2)
>                + 2*Z*covb1b4 + 2*W1*covb1b5 + 2*Z*W1*covb1b7 + 2*Z*W1*covb4b5
>                + 2*W1*(Z^2)*covb4b7 + 2*(W1^2)*Z*covb5b7);
{txt}(392 missing values generated)

{com}.                                            *     ****************************************************************  *;
. *                           Create t statistics                         *;
. *     ****************************************************************  *;
. gen t0=conb0/conse0;
{txt}(392 missing values generated)

{com}. gen t1=conb1/conse1;
{txt}(392 missing values generated)

{com}. *     ****************************************************************  *;
. *       Generate a `shadow' variable that is equal to the marginal      *;
. *       marginal effects that have already been calculated.  These will *;
. *       be helpful in placing the stars in the figure as you will see.  *;
. *     ****************************************************************  *;
. gen consb0=conb0;
{txt}(392 missing values generated)

{com}. gen consb1=conb1;
{txt}(392 missing values generated)

{com}. gen consb090=conb0;
{txt}(392 missing values generated)

{com}. gen consb190=conb1;
{txt}(392 missing values generated)

{com}. *     ****************************************************************  *;
. *       Make the `shadow' variable be missing if the t score is not     *;
. *       larger than the critical level of significance that you want.   *;
. *     ****************************************************************  *;
. replace consb0 = . if abs(t0)<1.645;
{txt}(7 real changes made, 7 to missing)

{com}. replace consb1 = . if abs(t1)<1.645;
{txt}(14 real changes made, 14 to missing)

{com}. replace consb090 = . if abs(t0)<1.28|abs(t0)>=1.645;
{txt}(18 real changes made, 18 to missing)

{com}. replace consb190 = . if abs(t1)<1.28|abs(t1)>=1.645;
{txt}(20 real changes made, 20 to missing)

{com}. *     ****************************************************************  *;
. *       Generate a string variable called str1 that is designated with  *;
. *       a star.                                                         *;
. *     ****************************************************************  *;
. generate str1 txt="*";
{txt}
{com}. generate str2 txt2="+";
{txt}
{com}. *     ****************************************************************  *;
. *       Graph the marginal effect of X on Y across the desired range of *;
. *       the modifying variable Z. Do this for when W=0 and for when W=1.*;
. *                                                                       *;
. *     ****************************************************************  *;
. graph twoway   line conb0  Z,  lpattern(dash) lwidth(medium)
>        ||  scatter consb0 Z,  mlabel(txt) msymbol(i) mlabsize(4) mlabgap(-1.0) mlabposition(11)
>        ||     line conb1  Z,  lpattern(solid) lwidth(medium)
>        ||  scatter consb1 Z,  mlabel(txt) msymbol(i) mlabsize(4) mlabgap(-1.0) mlabposition(11)  
>            ||  scatter consb090 Z,  mlabel(txt2) msymbol(i) mlabsize(4) mlabgap(-1.0) mlabposition(11)
>        ||  scatter consb190 Z,  mlabel(txt2) msymbol(i) mlabsize(4) mlabgap(-1.0) mlabposition(11)  
>        ||  ,   
>            xlabel(, labsize(5)) 
>            ylabel(, labsize(5))
>            yscale(noline)
>            xscale(noline)
>  xsize(3)
>            legend(order(1 "Low Motivation" 2 "High Motivation"))
>            xtitle(Trait Aggression, size(5))
>            ytitle(Marginal Treatment FX on Predicted Turnout Values, size(5))
>            xsca(titlegap(2)) 
>            ysca(titlegap(4))
>            scheme(s2mono) graphregion(fcolor(white));
{res}{txt}
{com}.            drop zmax zmin z0 Z conb0 conb1 consb090 consb190 conse0 conse1  t0 t1 consb0 consb1 txt txt2;
{txt}
{com}. 
{txt}end of do-file

{com}. log close
      {txt}name:  {res}<unnamed>
       {txt}log:  {res}C:\Users\nkalmoe\Dropbox\Research\A Publishing\Finished\PSRM - VCM Partic\Kalmoe - Fig A1, Study 2.smcl
  {txt}log type:  {res}smcl
 {txt}closed on:  {res}14 Jun 2017, 10:53:54
{txt}{.-}
{smcl}
{txt}{sf}{ul off}